package Demo03;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—14
 * Time: 17:50
 */

class OuterClass1{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    /**
     * 静态内部类
     * 1.如何拿到静态内部类的对象？
     * 外部类类名.内部类类名 变量 = new 外部类类名.内部类类名。
     *  OuterClass1.InnerClass innerClass = new OuterClass1.InnerClass();
     * 2.不能在静态内部类当中，直接访问外部类非静态的数据成员
     *必须要有对象的引用
     * */
    static class InnerClass{
        public int data4 =4;
        private int data5= 5;
        public static int data6 =6;
        public OuterClass1 outerClass1;

        public InnerClass(OuterClass1 outerClass1){
            System.out.println("静态内部类的构造方法！");
            this.outerClass1 = outerClass1;
        }
        public void test(){
            System.out.println("test方法执行了！");
            //访问外部类静态数据成员
/*          OuterClass1 outerClass = new OuterClass1();
            System.out.println(outerClass.data1);
            System.out.println(outerClass.data2);*/
            System.out.println(outerClass1.data1);
            System.out.println(outerClass1.data1);
            System.out.println(data4);
            System.out.println(data3);
            System.out.println(data5);
            System.out.println(data6);
        }
        public static void test2(){
            System.out.println("test2");
        }
    }

}
public class Test02 {
    public static void main(String[] args) {
        OuterClass1.InnerClass innerClass = new OuterClass1.InnerClass(new OuterClass1());
        innerClass.test();
    }
}
